<template>
  <div class="container">
    <div>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="选择日期：">
              <el-date-picker
                v-model="form.valueDay"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <!-- <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="班组：">
              <el-select v-model="teamValue" placeholder>
                <el-option
                  v-for="item in teamList"
                  :key="item.CLIENT_NAME"
                  :label="item.CLIENT_NAME"
                  :value="item.CLIENT_NAME"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col> -->
        <el-col :span="6">
          <el-form ref="form" :model="form" style="float:left">
            <el-button size="mini" type="primary" @click="getlistdata">查 询</el-button>
            <el-button size="mini" type="success" @click="exportExcel">导 出</el-button>
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table border :data="tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)" highlight-current-row>
      <el-table-column prop="VID" label="车辆ID" align="center"></el-table-column>
            <el-table-column prop="LICENSE_PLATE" label="车辆名称" align="center"></el-table-column>
            <el-table-column prop="CLIENT_NAME" label="所属" align="center"></el-table-column>
            <el-table-column prop="WORKTIME" label="行驶时间" align="center"></el-table-column>
            <el-table-column prop="LOCKTIME" label="作业时间" align="center"></el-table-column>
            <el-table-column prop="TPOINT" label="时间得分" align="center"></el-table-column>
            <el-table-column prop="DISTANCE" label="行驶里程" align="center"></el-table-column>
            <el-table-column prop="LOCKDISTANCE" label="作业里程" align="center"></el-table-column>
            <el-table-column prop="DPOINT" label="里程得分" align="center"></el-table-column>
            <el-table-column prop="ROADNUM" label="作业道路数" align="center"></el-table-column>
            <el-table-column prop="RPOINT" label="作业道路得分" align="center"></el-table-column>
            <el-table-column prop="STANDARDNUM" label="作业道路达标数" align="center"></el-table-column>
            <el-table-column prop="SPOINT" label="达标得分" align="center"></el-table-column>
            <el-table-column prop="SPEEDALARM" label="超速报警次数" align="center"></el-table-column>
            <el-table-column prop="STAYALAEM" label="滞留报警次数" align="center"></el-table-column>
            <el-table-column prop="ALARMPOINT" label="报警扣分" align="center"></el-table-column>
            <el-table-column prop="POINT" label="总分" align="center"></el-table-column>
      <!-- <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-info" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'
import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {
    return {
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      form: {
        radioData: '日',
        valueDay: formatDate(new Date(new Date() - 3600 * 1000 * 24), 'yyyy-MM-dd'),
        valueMonth: ''
      },
      teamList:[],
      teamValue:'全部',
      tableData: [],
      originalData: []
    }
  },
  created () {
    this.getTeamList()
    this.getlistdata()
  },
  methods: {
    async getTeamList () {
      const { data } = await this.$Http.get('DataListCompany/GetTeamListApi?ClientNo=' + localStorage.getItem('CLIENT_NO'))
      this.teamList = data
      this.teamList.unshift({"CLIENT_NO":"0","CLIENT_NAME":"全部"})
      // this.attendanceMonth.records.teamList = data
    },
    async getlistdata () {
      var url = 'Vehicle/GetPointInfo?ClientNo=' + localStorage.getItem('CLIENT_NO') + '&date=' + this.form.valueDay
      const { data } = await this.$Http.get(url)
      this.originalData = data
      // this.originalData = [{"VID":535,"WORKDATE":"2021-06-16","AM_IN":"06:28:50","AM_OUT":"11:00:49","PM_IN":"13:20:57","PM_OUT":"22:03:01","APOINT":40,"WORKCOUNT":"7.5","CPOINT":30,"WORKTIME":"224","TPOINT":30,"STAYALARM":0,"OUTALARM":0,"ALARMPOINT":0,"POINT":100,"NAME":"刘广梅","CLIENT_NAME":"张贵庄班组","df":0.0,"LONGITUDE":0.0,"LATITUDE":0.0,"DIRECTION":null},{"VID":541,"WORKDATE":"2021-06-16","AM_IN":"04:56:33","AM_OUT":"11:01:22","PM_IN":"13:25:36","PM_OUT":"17:31:09","APOINT":40,"WORKCOUNT":"19.1","CPOINT":30,"WORKTIME":"370","TPOINT":30,"STAYALARM":0,"OUTALARM":0,"ALARMPOINT":0,"POINT":100,"NAME":"孟广珍","CLIENT_NAME":"张贵庄班组","df":0.0,"LONGITUDE":0.0,"LATITUDE":0.0,"DIRECTION":null},{"VID":552,"WORKDATE":"2021-06-16","AM_IN":"04:46:50","AM_OUT":"11:04:35","PM_IN":"13:24:25","PM_OUT":"17:31:09","APOINT":40,"WORKCOUNT":"24.2","CPOINT":30,"WORKTIME":"456","TPOINT":30,"STAYALARM":0,"OUTALARM":0,"ALARMPOINT":0,"POINT":100,"NAME":"郭天利 ","CLIENT_NAME":"张贵庄班组","df":0.0,"LONGITUDE":0.0,"LATITUDE":0.0,"DIRECTION":null}]
      this.personQuery()
    },
    // 人员管理查询
    personQuery () {
      this.currentPage = 1;
      this.tableData = this.originalData
      // const { name, client } = this.person
      // if (name) this.tableData = this.tableData.filter(item => item.CLIENT_NAME.includes(name))
      if (this.teamValue != '全部') this.tableData = this.tableData.filter(item => this.teamValue == item.TITLE)
    },
    // 导出Excel
    exportExcel () {
      let excelName = '机扫作业绩效评分统计'
      const tHeader = ['车辆ID', '车辆名称', '所属', '行驶时间', '作业时间','时间得分', 
      '行驶里程', '里程得分', '作业道路数', '作业得分', '作业道路达标数', '达标得分', '滞留报警次数', '超速报警次数', '报警扣分', '总分']
      const filterVal = ['VID', 'LICENSE_PLATE', 'CLIENT_NAME', 'WORKTIME', 'LOCKDISTANCE', 'TPOINT', 
      'DISTANCE', 'DPOINT', 'ROADNUM', 'RPOINT', 'STANDARDNUM', 'SPOINT', 'STAYALAEM', 'SPEEDALARM', 'ALARMPOINT', 'POINT']
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },
    //详情
    handleEdit (index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
</style>